<template>
	<el-table :data="tableData" border style="width: 100%" :default-sort="{ prop: 'MAIN_NETINFLOW', order: 'descending' }">
		<el-table-column type="index" fixed></el-table-column>
		<el-table-column prop="INDEX_CODE" label="code" sortable fixed width="100"></el-table-column>
		<el-table-column prop="BOARD_NAME" label="名称" sortable fixed width="100"></el-table-column>

		<el-table-column prop="CHANGE_RATE" label="涨跌幅(%)" sortable
			:sort-method="(a, b) => { return a.CHANGE_RATE - b.CHANGE_RATE }" />
		<el-table-column prop="MAIN_NETINFLOW" label="涨跌额(元)" sortable></el-table-column>


	</el-table>
</template>

<script >

export default {
	// 北向资金
	data() {
		return {
			tableData: [],
		}
	},
	mounted() {
		this.data().then(data => this.tableData = data.result.data);
	},
	methods: {
		filterTag(value, row) {
			return row.TRADEMARKET === value;
		},
		sort(r1, r2) {
			//https://blog.csdn.net/shids_/article/details/129046419
			console.log(r1.VOLUME.replace("万", ""));
			console.log(parseFloat(r1.VOLUME));

			return parseFloat(r1.VOLUME) - parseFloat(r1.VOLUME);
		},
		data() {
			const options = {
				method: 'GET',
				url: 'https://datacenter.eastmoney.com/securities/api/data/get',
				params: {
					type: 'RPT_FUNDFLOW_BOARDCODE',
					sty: 'ALL',
					source: 'SECURITIES',
					client: 'WAP',
					filter: '(BOARD_TYPE="2")',
					extraCols: 'f3|06|INDEX_CODE|CHANGE_RATE,MAIN_NETINFLOW|06|INDEX_CODE|MAIN_NETINFLOW',
					p: '1',
					ps: '10',
					sr: '-1',
					st: 'MAIN_NETINFLOW'
				}
			};

			return new Promise((resolve, reject) => {
				axios.request(options).then(function (response) {
					console.log(response.data);
					return resolve(response.data);
				}).catch(function (error) {
					console.error(error);
				});
			});


		}
	}
}

</script>